/*
let reducers = combineReducers({
    // x:counter1 //0
    // , y:counter2 //0
    counter1
    ,counter2
});
*/

export default function(reducers){
    const reducerKeys = Object.keys(reducers); //['counter1','counter2']

    return function combination(state={},action){ //state={counter1:0,counter2:0}
        const nextState = {}; //下一个状态对象
        for(let i=0;i<reducerKeys.length;++i) {
            const key = reducerKeys[i];
            const reducer = reducers[key];

            //TODO[notice] important ↓
            const previousStateForKey = state[key];

            const nextStateForKey = reducer(previousStateForKey, action);
            nextState[key] = nextStateForKey;
        }
        return nextState;
    }
}

//problem↓
//每派发一个动作，所有子reducer都会遍历一遍
